// 角色管理相关的API请求函数

import request from '@/utils/request'

const prefix = '/dev-api'

// 获取权限(菜单/功能)列表 GET /admin/acl/permission
export const getPermissionList = () => request({ url: prefix + '/admin/acl/permission', method: 'get' })

// 删除一个权限项 DELETE /admin/acl/permission/remove/{id}
export const removePermission = (id) => request({ url: prefix + `/admin/acl/permission/remove/${id}`, method: 'delete' })

// 新增和修改的接口
export const reqAddOrUpdate = (permission) => {
  if (permission.id) {
    return request({ url: prefix + '/admin/acl/permission/update', method: 'put', data: permission })
  } else {
    return request({ url: prefix + '/admin/acl/permission/save', method: 'post', data: permission })
  }
}

// 保存一个权限项  POST /admin/acl/permission/save
export const addPermission = (permission) => request({ url: prefix + '/admin/acl/permission/save', method: 'post', data: permission })

// 更新一个权限项 PUT /admin/acl/permission/update
export const updatePermission = (permission) => request({ url: prefix + '/admin/acl/permission/update', method: 'put', data: permission })

// 查看某个角色的权限列表
export const reqGetToAssign = (roleId) => request({ url: prefix + `/admin/acl/permission/toAssign/${roleId}`, method: 'get' })

// 给某个角色授权 POST /admin/acl/permission/doAssign
export const doAssign = (roleId, permissionId) => request({ url: prefix + '/admin/acl/permission/doAssign', method: 'post', params: { roleId, permissionId }})

